    <?php
     
    class Correo{
        private static $nombre = '';
        private static $email = '';
        private static $mensaje = '';
        private static $template = '';
     
        private static $email_account = 'tu-email@domain.com';
        //private static $email_reply = 'reply@domain.com.ar';
        private static $name = 'NOMBRE';
     
     
     
        private static function set_values($params = NULL){
            if ($params !== NULL){
                foreach ($params as $key => $value){
                    self::$$key = $value;
                }
            }
        }
     
        public static function enviar($type, $params = NULL){
            self::set_values($params);
     
            if (!self::validar()){
                return false;
            }
     
            return self::$type();
        }
     
        private static function validar(){
            if (empty(self::$nombre)){
                Flash::error('Nombre Completo es requerido');
                return false;
            }
     
            if (empty(self::$email)){
                Flash::error('Correo es requerido');
                return false;
            }
     
            if (empty(self::$mensaje)){
                Flash::error('Comentario es requerido');
                return false;
            }
     
            return true;
        }
     
        private static function _initParams(){
            Load::lib('phpmailer');
            $mail = new PHPMailer();
    /*
            $mail->CharSet = 'utf-8';
            $mail->IsSMTP();
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = 'tls';
            $mail->Port = 25;
     
            $mail->Host = "mail.domain.com";
            $mail->Username = "user";
            $mail->Password = "password";
     
            $mail->SMTPDebug = 2;
            $mail->SMTPKeepAlive = true;
    */
            return $mail;
        }
     
        private static function enviarCorreo(){
            $mail = self::_initParams();
     
            $mail->SetFrom(self::$email, self::$nombre);
            $mail->AddReplyTo(self::$email, self::$nombre);
     
            $mail->AddAddress(self::$email_account, self::$name);
     
            $mail->Subject = "Mensaje de contacto - Sk84life Family";
     
            if (self::$template){
                $mail->IsHTML(true);
                ob_start();
                View::partial('emails/' . self::$template, false, array('params' => self));
                $mail->Body = ob_get_clean();
            }else{
                $mail->Body = strip_tags(self::$mensaje, '<br><br />');
            }
     
            $mail->AltBody = strip_tags(self::$mensaje, '<br><br />');
       
            $exito = $mail->Send();
     
            // Si el mensaje no ha podido ser enviado se realizaran 4 intentos
            $intentos=1;
            while ((!$exito) && ($intentos < 5)) {
                sleep(5);
                $exito = $mail->Send();
                $intentos++;
            }
     
            return $exito;
        }
    }
